package toolkit.tianshi.common.regular;

import java.util.regex.Pattern;

/**
 * 正则表达式，文本校验类
 * @author zhangLin
 */
public class RegularExpression {

    /**
     * PhoneNumber 电话用正则表达式
     */
    public enum PhoneNumber {
        /**
         * 手机号码（11位）
         */
        NORMAL,
        /**
         * 固定电话 3+7，8或4+7，8
         */
        FIXED_LINE,
        /**
         * 手机号（地区码+11位）
         */
        NumberCountry
    }

    public static boolean checkMobileNumber(String num, PhoneNumber type){
        String pattern = "";
        switch (type) {
            case NORMAL: pattern = Expression.mobileNumberNormal; break;
            case FIXED_LINE: pattern = Expression.fixedLineNumber; break;
            case NumberCountry: pattern = Expression.mobileNumberCountry; break;
            default: new RuntimeException("parameter is error");
        }
        return Pattern.matches(pattern, num);
    }

    public static boolean checkEmail(String mail) {
        String pattern = Expression.eMailAddress;
        return Pattern.matches(pattern, mail);
    }
}
